package com.lagou.myspringboot.config;

import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;

import javax.servlet.ServletException;

public class SpringApplication {

    public void start(){
        Tomcat tomcat=new Tomcat();
        tomcat.setPort(8080);
        tomcat.setBaseDir(".");
        tomcat.setBaseDir(".");
        try {
            //设置项目文件路径
            tomcat.addWebapp("/", "G:\\");
            tomcat.start();
            //  监听关闭端口，阻塞式。没有这一句，方法执行完会直接结束
            tomcat.getServer().await();
        } catch (LifecycleException e) {
            e.printStackTrace();
        } catch (ServletException e) {
            e.printStackTrace();
        }
    }
}
